
#ifndef _TOS_SECURE_PORT_H_
#define  _TOS_SECURE_PORT_H_
#include <stddef.h>
#include <stdint.h>
#include "port_config.h"

/* CPP header guards */
#ifdef __cplusplus
#define __CDECLS_BEGIN          extern "C" {
#define __CDECLS_END            }
#else
#define __CDECLS_BEGIN
#define __CDECLS_END
#endif

#define __INLINE__          inline
#define __STATIC__          static
#define __STATIC_INLINE__   static inline
/* CPU address type based on address bus size.          */
#if     (TOS_CFG_CPU_ADDR_SIZE == CPU_WORD_SIZE_32)
typedef uint32_t    cpu_addr_t;
#elif   (TOS_CFG_CPU_ADDR_SIZE == CPU_WORD_SIZE_16)
typedef uint16_t    cpu_addr_t;
#else
typedef uint8_t     cpu_addr_t;
#endif
/**tos_ktypes.h*/
#ifndef K_NULL
#define  K_NULL             0
#endif
#define K_TRUE              (0u)
#define K_FALSE             (-1u)

/**tos_cpu.h */
/* CPU data type based on data bus size.          */
#if     (TOS_CFG_CPU_DATA_SIZE == CPU_WORD_SIZE_32)
typedef uint32_t    cpu_data_t;
#elif   (TOS_CFG_CPU_DATA_SIZE == CPU_WORD_SIZE_16)
typedef uint16_t    cpu_data_t;
#else
typedef uint8_t     cpu_data_t;
#endif

/**tos_klib.h */
#define __MACRO_BEGIN        do {
#define __MACRO_END          } while (0)
#define TOS_PTR_SANITY_CHECK(ptr)               \
    __MACRO_BEGIN                               \
        if (unlikely(!(ptr))) {                 \
            return K_ERR_OBJ_PTR_NULL;          \
        }                                       \
    __MACRO_END

#define TOS_PTR_SANITY_CHECK_RC(ptr, return_code)           \
    __MACRO_BEGIN                                           \
        if (unlikely(!(ptr))) {                             \
            return return_code;                             \
        }                                                   \
    __MACRO_END

#define TOS_OFFSET_OF_FIELD(type, field)    \
    ((uint32_t)&(((type *)0)->field))

#if defined(TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT) && (TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT == 1u)
uint32_t   port_clz(uint32_t val);
#endif
uint32_t tos_cpu_clz(uint32_t val);
#endif